package cn.taofuxn.sale.controller;

import cn.taofuxn.sale.controller.data.AddOrderRequest;
import cn.taofuxn.sale.controller.data.ModifyOrderRequest;
import cn.taofuxn.sale.controller.data.QueryOrderRequest;
import cn.taofuxn.sale.service.SaleService;
import cn.taofuxn.sale.service.data.base.BaseResult;
import io.swagger.annotations.Api;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * ProjectName : GeekSaleSystem
 * PackageName : cn.taofuxn.sale.controller
 * Created by Wong
 * Date: 2018/3/20
 * Time: 15:24
 */
@Api(value = "saleController" ,description = " 订单管理")
@RestController
@RequestMapping(value = "/sale")
public class SaleController {
	
	@Autowired
	private SaleService m_SaleService;
	
	@RequestMapping(value = "/getOrders",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
	public BaseResult getOrders(@RequestBody QueryOrderRequest vRequest){
		return m_SaleService.getOrders(vRequest.getPage(), vRequest.getPagesize(), vRequest.getStartTime(), vRequest.getEndTime());
	}
	
	@RequestMapping(value = "/addOrder",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
	public BaseResult addOrder(@RequestBody AddOrderRequest vRequest){
		return m_SaleService.addOrder(vRequest);
	}
	
	@RequestMapping(value = "/modifyOrder",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
	public BaseResult modifyOrder(@RequestBody ModifyOrderRequest vRequest){
		return m_SaleService.modifyOrder(vRequest);
	}
	
	@RequestMapping(value = "/deleteOrder",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
	public BaseResult deleteOrder(@Valid @NotBlank @RequestParam  String vOrderId){
		return m_SaleService.deleteOrder(vOrderId);
	}

}
